package leetcode;

public class Code29 {
    public static void main(String[] args) {
        int a=-2147483648;
        System.out.println(a);
        //System.out.println(new Code29().divide(-2147483648,-1));
    }
    public int divide2(int dividend, int divisor) {
        long a=(long)dividend/(long)divisor;
        if(a>2147483647){
            return 2147483647;
        }else if(a<=-2147483648){
            return -2147483648;
        }else{
            return (int)a;
        }
    }
    public int divide(int dividend, int divisor) {
        return dividend*divisor<0?
                -getReturnNumber(getS(dividend),getS(divisor),0):
                getReturnNumber(getS(dividend),getS(divisor),0);
    }
    private int getS(int a){
        return a<0?-a:a;
    }
    public int getReturnNumber(int dividend, int divisor,int speed){
        if(dividend-divisor>0){
            speed++;
            return getReturnNumber(dividend-divisor,divisor,speed);
        }else{
            return dividend-divisor==0?++speed:speed;
        }
    }
}
